package com.kingdee.shr.perfweb.publicity.handler;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.ModelMap;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.web.handler.SHRSubBasicItemEditHandler;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
import com.kingdee.shr.perfweb.app.base.perfmancescore.PerfScorLevelDefineCollection;
import com.kingdee.shr.perfweb.app.base.perfmancescore.PerfScorLevelDefineFactory;
import com.kingdee.shr.perfweb.app.base.perfmancescore.PerfScorLevelDefineInfo;

public class PublicityRuleConfigEditHandler extends SHRSubBasicItemEditHandler {
	public String getConfigDefineAction(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap)
			throws SHRWebException {
		try {
			Context ctx = SHRContext.getInstance().getContext();
			Map map = new HashMap();
			JSONObject json = new JSONObject();
			JSONArray array = new JSONArray();
			String id = request.getParameter("id");
			PerfScorLevelDefineCollection collection = PerfScorLevelDefineFactory.getLocalInstance(ctx).getPerfScorLevelDefineCollection("where perfScoreLevel.id = '"+id+"' order by showNumber");
			PerfScorLevelDefineInfo defineInfo;
			for(int i = 0,size = collection.size(); i < size; i++){
				defineInfo = collection.get(i);
				json = new JSONObject();
				json.put("showNumber", defineInfo.getShowNumber());
				json.put("perfLevelName", defineInfo.getPerfLevelName());
				json.put("sysPerfLevel", defineInfo.getSysPerfLevel());
				json.put("simpleName", defineInfo.getString("id"));
				array.add(json);
			}
			map.put("rows", array);
			JSONUtils.writeJson(response, map);
		} catch (BOSException e) {
			e.printStackTrace();
		}
		return null;
	}
}
